#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
struct ss
{
	string str;
	int jg;
}a[1010], b[1010], c[1010];

bool cmp(ss x, ss y)
{
	return x.jg < y.jg;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int sum = 0;
		int s, m, d;
		cin >> s >> m >> d;
		for (int i = 1; i <= s; i++)
			cin >> a[i].str >> a[i].jg;
		for (int i = 1; i <= m; i++)
			cin >> b[i].str >> b[i].jg;
		for (int i = 1; i <= d; i++)
			cin >> c[i].str >> c[i].jg;

		sort(a + 1, a + s + 1, cmp);
		sort(b + 1, b + m + 1, cmp);
		sort(c + 1, c + d + 1, cmp);

		int x = a[s / 2 + 1].jg; string q = a[s / 2 + 1].str;
		int y = b[m / 2 + 1].jg; string w = b[m / 2 + 1].str;
		int z = c[d / 2 + 1].jg; string e = c[d / 2 + 1].str;

		sum = x + y + z;
		cout << sum << " " << q << " " << w << " " << e << endl;
	}
	return 0;
}